<?

# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
#
#	FILE:			includes/date.php
#	FUNCTION:		Date-related functions
#	AUTHOR:			Cameron Morrow
#	CREATED:		26/07/2005
#
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -


$MONTH_ARRAY = array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");

$YEAR_ARRAY = array("2000", "2001", "2002", "2003", "2004", "2005", "2006", "2007", "2008", "2009", "2010", "2011", "2012", "2013", "2014", "2015", "2016", "2017", "2018", "2019", "2020");

$MONTH_NUM_ARRAY = array("01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12");

$DAY_ARRAY = array("01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31");

$QUARTER_MINUTE_ARRAY = array("00", "15", "30", "45");

$HOUR_ARRAY = array("00", "01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23");

$AM_PM_ARRAY = array("AM", "PM");


/**
 * formatDBDate() formats a date passed in the format used in the database: YYYYMMDDHHMM
 *
 * @param $unformatted is the unformatted date
 *
 * @return the date formatted as a string
*/
function formatDate($unformatted = "", $date_format = "d M Y g:ia") {

	if ($unformatted != "") {

		# Compose valid time
		$valid_time = substr($unformatted, 4, 2) . "/" . substr($unformatted, 6, 2) . "/" . substr($unformatted, 0, 4) . " " . substr($unformatted, 8, 	2) . ":" . substr($unformatted, 10, 2);
		
		if (strlen($unformatted) == 14) {
			$valid_time .= ":" . substr($unformatted, 12, 2);
		}

		return date($date_format, strtotime($valid_time));
	} else {
		return "<span class=\"disabled\">N/A</span>";
	}
}


/**
 * getFullDate() gets the current date in YYYYMMDDHHMM format
 *
 * @param with_seconds is whether seconds should be included
 *
 * @return the date in YYYYMMDDHHMM(SS)
*/
function getFullDate($with_seconds = false) {

	return date("YmdHis");
}


/**
 * addZeros returns a string with padded zeros on the front
 *
 * @param input is the input string
 * @param total_length is the length of the string to create
 *
 * @return the padded string
*/
function addZeros($input = "", $total_length = 0) {
	return str_pad($input, $total_length, "0", STR_PAD_LEFT);
}

?>